// pages/sort/sort.js

const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    statusBarHeight: '',
    title:[
      {
        name:'新品',
        id:'new-product'
      },
      {
        name:'众筹',
        id:'crowdfunding'
      },
      {
        name:'小米手机',
        id:'xiaomi-phone'
      },
      {
        name:'Redmi',
        id:'redmi-phone'
      },
      {
        name:'黑鲨',
        id:'heisha-phone'
      },
      {
        name:'5G合约',
        id:'five-g'
      },
      {
        name:'手机配件',
        id:'phone-fitting'
      },
      {
        name:'电视',
        id:'tv'
      },
      {
        name:'大家电',
        id:'appliance'
      },
      {
        name:'电脑办公',
        id:'pc'
      },
      {
        name:'小爱智能',
        id:'xiaoai'
      },
      {
        name:'路由器',
        id:'router'
      },
      {
        name:'生活电器',
        id:'home-devices'
      },
      {
        name:'厨房电器',
        id:'kitchen-appliances'
      },
      {
        name:'智能穿戴',
        id:'smart-wear'
      },
      {
        name:'智能家居',
        id:'smart-home'
      },
      {
        name:'车载出行',
        id:'travel-by-car'
      },
      {
        name:'个护健康',
        id:'health-care'
      },
      {
        name:'数码配件',
        id:'digital-accessories'
      },
      {
        name:'日用百货',
        id:'daily-necessities'
      },
      {
        name:'有品精选',
        id:'featured'
      },
      {
        name:'服务',
        id:'serving'
      },
      {
        name:'米粉卡',
        id:'mi-card'
      },
      {
        name:'生活商品',
        id:'commodity'
      },
      {
        name:'零售店',
        id:'retail-store'
      }
    ],
    curIndex:0,  //初始化当前下标为0
    toView:"new-product", //默认显示“新品展示”
    detail:[]
  },
  switchCategory(e){
    const curIndex=e.currentTarget.dataset.index?e.currentTarget.dataset.index:0;  //获取每个菜单的id
    //更新数据
    this.setData({
      toView:e.currentTarget.dataset.id,
      curIndex:curIndex
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    /*wx.request({
      url: 'http://47.107.136.222/test', 
      data: {
        x: '',
        y: ''
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        console.log('请求');
        console.log(res.data)
      }
    })*/
    this.setData({
      statusBarHeight: app.globalData.statusBarHeight + 8
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})